package com.park.manage.service.park.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.park.comm.ResultEnum;
import com.park.dao.mapper.park.ParkInfoMapper;
import com.park.entity.page.PageInfoParm;
import com.park.entity.park.ParkInfo;
import com.park.entity.park.ParkInfoItem;
import com.park.exception.CommException;
import com.park.manage.service.park.ManageParkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author ZhangHaiWen
 * @title: ManageParkServiceImpl
 * @projectName park
 * @description:  商户停车场
 * @date 2020/5/720:34
 */
@Service(value = "manageParkService")
public class ManageParkServiceImpl implements ManageParkService {

    @Autowired
    private ParkInfoMapper parkInfoMapper;

    /**
     * 添加停车场
     * @param parkInfo
     */
    public void addParkInfo(ParkInfo parkInfo) {
        String parkName = parkInfo.getParkName();
        if(StrUtil.isEmpty(parkName)){
            throw new CommException(ResultEnum.PARK_NAME_EMPTY_ERROR);
        }
        if(ObjectUtil.isEmpty(parkInfo.getParkLat()) || ObjectUtil.isEmpty(parkInfo.getParkLong()) ){
            throw new CommException(ResultEnum.PARK_ADDRESS_EMPTY_ERROR);
        }
        BigDecimal parkHourFee = parkInfo.getParkHourFee();
        BigDecimal parkLabour = parkInfo.getParkLabour();
        if(ObjectUtil.isEmpty(parkHourFee) || ObjectUtil.isEmpty(parkLabour) || parkHourFee.compareTo(BigDecimal.ZERO) < 0 || parkLabour.compareTo(BigDecimal.ZERO)<0){
            throw new CommException(ResultEnum.PARK_FEE_EMPTY_ERROR);
        }
        long timeMillis = System.currentTimeMillis();
        parkInfo.setTimeStamp(timeMillis);
        parkInfo.setAddTimeStamp(timeMillis);
        parkInfoMapper.insert(parkInfo);
    }

    /**
 　　* @description:  停车场列表
 　　* @param [pageInfoParm]
 　　* @return {@link PageInfo< ParkInfoItem>}
 　　* @throws
 　　* @author ZhangHaiWen
 　　* @version 2.0
 　　* @date 2020/5/7 20:54PageHelper
 　　*/
    public PageInfo<ParkInfoItem> list(PageInfoParm pageInfoParm) {
        PageHelper.startPage(pageInfoParm.getPageNum(), pageInfoParm.getPageSize());
        List<ParkInfoItem> parkInfoItemList = parkInfoMapper.list();
        PageInfo<ParkInfoItem> pageInfo = new PageInfo<ParkInfoItem>(parkInfoItemList);
        return pageInfo;
    }
}
